var earnestTable = {
    id: "earnestTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

earnestTable.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 120},
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true, width: 140},
        {title: 'TC', field: 'tcName', align: 'center', valign: 'middle', sortable: true, width: 90},
        {title: '操作方式', field: 'mode', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '缴费', field: 'actualAccountBalance', align: 'center', valign: 'middle', sortable: true, width: 120},
        {title: '缴费方式', field: 'checkoutMethod', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '转账人', field: 'customerNameZZ', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                if(row.customerNameSF != ""){
                    return row.customerName;
                }else {
                    return value;
                }
            }
        },
        {title: '收费人', field: 'customerNameSF', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                if(row.customerNameZZ != ""){
                    return row.customerName;
                }else {
                    return value;
                }
            }
        },
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true, width: 130},
        {title: '操作人', field: 'rechargePeople', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '操作门诊', field: 'addStore', align: 'center', valign: 'middle', sortable: true, width: 120},
        {title: '缴费时间', field: 'rechargeTime', align: 'center', valign: 'middle', sortable: true, width: 170,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '操作', field: 'id', align: 'center', valign: 'middle', sortable: true,width: 100,
            formatter: function (value, row, index) {
                return '<span onclick="reserveMoneyPrint(' + "'" + row.id+ "'" + ')" style="cursor: pointer">【打印】</span>'
            }
        }
    ];
    return columns;
};

function reserveMoneyPrint(id){ //打印储值记录
    var index = layer.open({
        type: 2,
        title: '打印',
        area: ['60%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/reserveMoney_Print/' + id // 传入选中行的客户ID
    });
    this.layerIndex = index;
}

earnestTable.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        earnestTable.seItem = selected[0];
        return true;
    }
};

earnestTable.choiceEarnestDealTc = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '选择Tc',
            area: ['50%', '60%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/earnest_choiceTc/'+ earnestTable.seItem.id
        });
        this.layerIndex = index;
    }
};

earnestTable.search = function () {
    earnestTable.table.refresh();
};

$(function () {
    var defaultColunms = earnestTable.initColumn();
    var reservationsId = parent.$("#reservationsId").val();
    var table = new BSTable(earnestTable.id, "/customer/getEarnestList/" + reservationsId, defaultColunms);
    table.setPaginationType("client");//客户端分页
    earnestTable.table = table.init();
    earnestTable.search();
});